// packageB/pages/express/express.js
// pages/Goods/goodsOrder/index.js
var common = require("../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        expressCompany:"",
        expressStaus:'',
        expressName: '', //快遞名稱
        expressNumber: '',
        numberExpress: '',
        logo: '',
        picPath: "http://feiyangimage.oss-cn-shanghai.aliyuncs.com/regionAdvertisement/1650012371052914.jpeg",
        active: 0,
        steps: [],
        
    },


    /**
     * 生命周期函数--监听页面加载
     */
    // 複製
    copy() {
        wx.setClipboardData({
            data: this.data.expressNumber,
            success(res) {
                wx.getClipboardData({
                    success(res) {
                        console.log(res.data)
                    }
                })
            }
        })

    },
    // 查看物流信息
    lookPackage() {
        var that = this;
        common.post('/getExpressInfo', {
                postId: this.data.expressNumber
            },
            function (res) {
                if (res.code == 200) {
                    that.setData({
                        logo: res.logo,
                        expressName: res.expName,
                        numberExpress: res.number
                    })
                    var objBig ={}
                    var arr =[]
                    for(var i =0;i<res.data.length;i++){
                       for(let key in res.data[i]){
                         if(key == 'time'){
                           var obj ={'text':res.data[i][key]}
                         }else if(key == 'status'){
                           var objs ={'desc':res.data[i][key]}
                         }
                       }
                       objBig = {...obj,...objs}
                       arr.push(objBig)
                    }
                    that.setData({
                        steps:arr
                    })
                    var str = ''
                    switch (parseInt(res.deliverystatus)) {
                        case 0:
                            str = '快递收件（揽件）'
                            break;
                        case 1:
                            str = '在途中'
                            break;
                        case 2:
                            str = '正在派件'
                            break;
                        case 3:
                            str = '已签收'
                            break;
                        case 4:
                            str = '派送失败'
                            break;
                        default:
                            str = '疑难件'
                    }
                     that.setData({
                         expressStaus:str
                     })
                } 

            })

    },
    onLoad: function (options) {
      
        if (options.expressNumber && options.storeImage) {
            this.setData({
                expressNumber: options.expressNumber,
                picPath: options.storeImage,
                expressCompany:options.expressCompany
            }, () => {
                this.lookPackage()
            })
        }
    },

    
})